home *** CD-ROM | disk | FTP | other *** search
/ Aminet 5 / Aminet 5 - March 1995.iso / Aminet / dev / misc / LEDA_gene.lha / LEDA-3.1c-generic / incl / LEDA / impl / ch_hash1.h < prev    next >
Encoding:
C/C++ Source or Header  |  1994-08-05  |  3.0 KB  |  131 lines

  1. /*******************************************************************************
  2. +
  3. +  LEDA  3.1c
  4. +
  5. +
  6. +  ch_hash1.h
  7. +
  8. +
  9. +  Copyright (c) 1994  by  Max-Planck-Institut fuer Informatik
  10. +  Im Stadtwald, 6600 Saarbruecken, FRG     
  11. +  All rights reserved.
  12. *******************************************************************************/
  13.  
  14.  
  15. #ifndef LEDA_CH_HASHING1_H
  16. #define LEDA_CH_HASHING1_H
  17.  
  18. //------------------------------------------------------------------------------
  19. // Hashing with Chaining
  20. //
  21. // S. Naeher  (1994)
  22. //
  23. //------------------------------------------------------------------------------
  24.  
  25. #include <LEDA/basic.h>
  26.  
  27.  
  28. //------------------------------------------------------------------------------
  29. // class ch_hash1_elem  
  30. //------------------------------------------------------------------------------
  31.  
  32. class ch_hash1_elem 
  33. {
  34.   friend class ch_hash1;
  35.  
  36.   ch_hash1_elem* succ;
  37.   GenPtr k;
  38.   GenPtr i;
  39.  
  40.  
  41.   public:
  42.  
  43.   ch_hash1_elem(GenPtr key, GenPtr inf, ch_hash1_elem* next = 0) 
  44.   { k = key; 
  45.     i = inf; 
  46.     succ = next;
  47.    }
  48.  
  49.   ch_hash1_elem() {}
  50.  
  51.   LEDA_MEMORY(ch_hash1_elem)
  52.  
  53. };
  54.  
  55. typedef ch_hash1_elem*  ch_hash1_item;
  56.  
  57.  
  58. //--------------------------------------------------------------------
  59. // class ch_hash1
  60. //--------------------------------------------------------------------
  61.  
  62. class ch_hash1 
  63. {
  64.  
  65.    static ch_hash1_elem STOP;
  66.  
  67.    ch_hash1_elem* table;
  68.  
  69.    int table_size;           
  70.    int table_size_1;           
  71.    int low_table;           
  72.    int high_table;           
  73.    int count;
  74.  
  75.  
  76.    virtual int hash_fct(GenPtr x)      const { return long(x); }
  77.    virtual int cmp(GenPtr x, GenPtr y) const { return compare(x,y); }
  78.    virtual void clear_key(GenPtr&)  const { }
  79.    virtual void clear_inf(GenPtr&)  const { }
  80.    virtual void copy_key(GenPtr&)   const { }
  81.    virtual void copy_inf(GenPtr&)   const { }
  82.    virtual void print_key(GenPtr)   const { }
  83.  
  84.    virtual int_type() const { return 0; }
  85.  
  86.    int  next_pow(int) const;
  87.    void init(int);
  88.    void rehash(int);
  89.    void destroy();
  90.    ch_hash1_item search(GenPtr,ch_hash1_item&) const;
  91.  
  92.    protected:
  93.  
  94.    ch_hash1_item item(GenPtr p) const { return ch_hash1_item(p) ; }
  95.  
  96.    public:
  97.  
  98.    ch_hash1_item lookup(GenPtr x) const;
  99.  
  100.    ch_hash1_item insert(GenPtr,GenPtr);
  101.  
  102.    ch_hash1_item first_item() const { return 0; }
  103.    ch_hash1_item next_item(ch_hash1_item) const { return 0; }
  104.  
  105.    void del(GenPtr);
  106.    void del_item(ch_hash1_item);
  107.  
  108.    bool member(GenPtr x)   const  { return ( lookup(x) ? true : false ); } 
  109.  
  110.    GenPtr  key(ch_hash1_item p)  const { return p->k; }
  111.    GenPtr  inf(ch_hash1_item p)  const { return p->i; }
  112.    GenPtr& info(ch_hash1_item p)       { return p->i; }
  113.  
  114.    void change_inf(ch_hash1_item, GenPtr);
  115.    bool empty() const     { return count ? false : true ; } 
  116.    int  size()  const     { return count; } 
  117.    int  tablesize() const { return table_size ; }
  118.    void clear()           { destroy(); init(table_size);}
  119.  
  120.    ch_hash1& operator=(const ch_hash1&);
  121.    ch_hash1(const ch_hash1&);
  122.  
  123.    ch_hash1(int ts = 1<<10) { init(ts); /* init(next_pow(ts)); */ }
  124.    virtual ~ch_hash1()     { destroy(); }
  125.  
  126. };
  127.  
  128.  
  129. #endif
  130.